const baseUrl = 'https://hh.sc.yifckj.com/api/';   

import qs from './qs.js'
const accessToken = '74be16979710d4c4e7c6647856088456'; //uni.getStorageSync("accessToken");
const header = {
	'content-type': 'application/json',
};
export const apiget = (url = '', date = {}) => {
	uni.showLoading({
		mask:true,
	})
	return new Promise((resolve, reject) => {
		uni.request({
			method: "GET",
			url:baseUrl+url,
			data: date,
			header: header,
			dataType: 'json',
		}).then((response) => {
			setTimeout(function() {
				uni.hideLoading();
			}, 200);
			let [error, res] = response;
			if (res.statusCode === 200) {
			    //成功
			    if (res.data.code == 0) {
			        uni.showModal({
			            title: '系统提示',
			            content: res.data.msg || '系统错误',
			            showCancel: false
			        });
			    } else if (res.data.code == 403) {
			        uni.reLaunch({
			            url: '/pages/Authorizedlogin/Authorizedlogin'
			        });
			    } else {
			        resolve(res.data);
			    }
			} else {
			    uni.showModal({
			        title: '系统提示',
			        content: res.data.msg || '系统错误',
			        showCancel: false
			    });
			}
			
			// resolve(res.data);
		}).catch(error => {
			let [err, res] = error;
			reject(err)
		})
	});
}

// export const apipost = (url = '', date = {}) => {
// 	uni.showLoading({
// 		mask:true,
// 	})
// 	return new Promise((resolve, reject) => {
// 		uni.request({
// 			method: "POST",
// 			url:baseUrl+url,
// 			data: qs.stringify(date),
// 			header: header,
// 			dataType: 'json',
// 		}).then((response) => {
// 			setTimeout(function() {
// 				uni.hideLoading();
// 			}, 200);
// 			let [error, res] = response;
// 			resolve(res.data);
// 		}).catch(error => {
// 			let [err, res] = error;
// 			reject(err)
// 		})
// 	});
// }
